﻿(function ($) {

    $.animateMenu = function (employee, btnRedraw, mainDiv, hUserInfo, hLottery, winner, timeFrame) {
        
        var i, T, Winner;
        var randomString = new Array();
        var userInfo = new Array();

        $(hUserInfo).hide();
        GetUserInfo();
        DataRotation();



        $(btnRedraw).click(function () {
            $(winner).hide();
            $(hUserInfo).hide();
            GetUserInfo();
            DataRotation();

        });

        function GetUserInfo() {
            if (employee.length > 0) {
                for (i = 0; i < employee.length; i++) {
                    randomString[i] = employee[i].email;
                    userInfo[i] = employee[i].FirstName + "" + employee[i].LastName;
                }
                WinnerOfTheDay();
            }
        }
        function WinnerOfTheDay() {
            Winner = Math.floor(randomString.length * Math.random());
        }

        function DataRotation() {
            var j = 0;
            T = setInterval(function () {
                if (document.all)
                    document.all.hLottery.innerHTML = userInfo[j];
                if (document.getElementById)
                    document.getElementById('hLottery').innerHTML = userInfo[j];
                j++;
                if (j >= randomString.length) {
                    clearTimeout(T);
                    MakeWinnerVisible();
                }
            }, timeFrame);

        }

        function MakeWinnerVisible() {
            document.getElementById('hUserInfo').innerHTML = userInfo[Winner];
            document.getElementById('hLottery').innerHTML = randomString[Winner];
            $(winner).show();
            $(hUserInfo).show();
        }
    }
})(jQuery);